package cz.tomasdvorak.cars.wicket.components.table;

import org.apache.wicket.extensions.markup.html.repeater.data.table.*;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.OddEvenItem;
import org.apache.wicket.model.IModel;


/**
 * An implementation of the DataTable that aims to solve the 90% usecase by adding navigation,
 * headers, an no-records-found toolbars to a standard {@link DataTable}.
 * <p>
 * The {@link NavigationToolbar} and the {@link HeadersToolbar} are added as top toolbars, while the
 * {@link NoRecordsToolbar} toolbar is added as a bottom toolbar.
 *
 * @see DataTable
 * @see HeadersToolbar
 * @see NavigationToolbar
 * @see NoRecordsToolbar
 *
 * @author Igor Vaynberg ( ivaynberg )
 */
public class EnhancedDataTable<T> extends DataTable<T> {
	private static final long serialVersionUID = 1L;

    /**
     * Constructor without paging.
     *
     * @param id
     *            component id
     * @param columns
     *            array of columns
     * @param dataProvider
     *            data provider
     */
    public EnhancedDataTable(String id, final IColumn<T>[] columns, ISortableDataProvider<T> dataProvider) {
        super(id, columns, dataProvider, Integer.MAX_VALUE);

        addTopToolbar(new HeadersToolbar(this, dataProvider));
        addBottomToolbar(new LocalizableNoRecordsToolbar(this));
    }

	/**
	 * Constructor
	 *
	 * @param id
	 *            component id
	 * @param columns
	 *            array of columns
	 * @param dataProvider
	 *            data provider
	 * @param rowsPerPage
	 *            number of rows per page
	 */
	public EnhancedDataTable(String id, final IColumn<T>[] columns, ISortableDataProvider<T> dataProvider,
			int rowsPerPage) {
		super(id, columns, dataProvider, rowsPerPage);

		addTopToolbar(new HeadersToolbar(this, dataProvider));
        addBottomToolbar(new LocalizableNoRecordsToolbar(this));
        addBottomToolbar(new StyledNavigationToolbar(this));
    }

	protected Item<T> newRowItem(String id, int index, IModel<T> model) {
		return new OddEvenItem<T>(id, index, model);
	}
}
